//
//  CellForSection1.m
//  ProjectA
//
//  Created by dllo on 16/1/21.
//  Copyright © 2016年 刘旺辉. All rights reserved.
//

#import "CellForSection1.h"
#import "NetWorkHandler.h"
#import "ModelForSection1.h"
#import <UIImageView+WebCache.h>
#import "AppMacro.h"

@interface CellForSection1 ()

@property (nonatomic, strong) UIImageView *index_cover;
@property (nonatomic, strong) UILabel *index_title;
@property (nonatomic, strong) UIImageView *avatar_s;
@property (nonatomic, strong) UILabel *name;
@end

@implementation CellForSection1

- (void)dealloc {
    
    [_name release];
    [_avatar_s release];
    [_index_title release];
    [_index_cover release];
  
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    
    if (self) {
        
    
        // 初始化控件
        [self createSubView];

    }
    return self;
}

- (void)createSubView {
    
    self.index_cover = [[UIImageView alloc] init];
    [self.contentView addSubview:self.index_cover];
    [_index_cover release];
    
    self.index_title = [[UILabel alloc] init];
    [self.contentView addSubview:self.index_title];
    [_index_title release];
    
    self.avatar_s = [[UIImageView alloc] init];
    [self.contentView addSubview:self.avatar_s];
    [_avatar_s release];
    
    self.name = [[UILabel alloc] init];
    [self.contentView addSubview:self.name];
    [_name release];
    
}


- (void)applyLayoutAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes {
 
    self.layer.cornerRadius = 7;
    self.layer.masksToBounds = YES;
    
    self.index_cover.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height * 1.7 / 3);
    
    
    self.index_title.frame = CGRectMake(8, self.frame.size.height * 1.7 / 3 + 10, self.frame.size.width - 16, 50);
    self.index_title.numberOfLines = 0;
    
    
    self.avatar_s.frame = CGRectMake(8, self.frame.size.height * 1.7 / 3 + 10 + 50 + 5, 30, 30);
    self.avatar_s.layer.cornerRadius = 15;
    self.avatar_s.layer.masksToBounds = YES;
    
    
    self.name.frame = CGRectMake(45, self.frame.size.height * 1.7 / 3 + 10 + 50 + 5, self.frame.size.width - 50, 30);
    self.name.font = [UIFont systemFontOfSize:13];
    
    
    [UIView setColorWithView:self.contentView nightColor:L_COLOR_GRAY dayColor:L_COLOR_WHITE];
    
    [UIView setColorWithLabelText:self.index_title nightColor:L_COLOR_WHITE dayColor:L_COLOR_BLACK];
    
    [UIView setColorWithLabelView:self.index_title nightColor:L_COLOR_GRAY dayColor:L_COLOR_WHITE];
    
    [UIView setColorWithLabelText:self.name nightColor:L_COLOR_WHITE dayColor:L_COLOR_LIGHTGRAY];
    
}

- (void)passModel:(ModelForSection1 *)model {
    
    
    [self.index_cover sd_setImageWithURL:[NSURL URLWithString:model.cover_image_s] placeholderImage:[UIImage imageNamed:@"iconfont-zhanweitu"]];
    self.index_title.text = model.index_title;
    [self.avatar_s sd_setImageWithURL:[NSURL URLWithString:model.avatar_s]];
    self.name.text = model.name;
    
}



@end
